import("//llvm/utils/TableGen/tablegen.gni")

declare_args() {
  # Buggy, only use if you know what you're doing.
  x86_gen_fold_tables = false
}

tablegen("X86GenCallingConv") {
  visibility = [ ":LLVMX86CodeGen" ]
  args = [ "-gen-callingconv" ]
  td_file = "X86.td"
}

tablegen("X86GenDAGISel") {
  visibility = [ ":LLVMX86CodeGen" ]
  args = [ "-gen-dag-isel" ]
  td_file = "X86.td"
}

tablegen("X86GenEVEX2VEXTables") {
  visibility = [ ":LLVMX86CodeGen" ]
  args = [ "-gen-x86-EVEX2VEX-tables" ]
  td_file = "X86.td"
}

tablegen("X86GenFastISel") {
  visibility = [ ":LLVMX86CodeGen" ]
  args = [ "-gen-fast-isel" ]
  td_file = "X86.td"
}

tablegen("X86GenGlobalISel") {
  visibility = [ ":LLVMX86CodeGen" ]
  args = [ "-gen-global-isel" ]
  td_file = "X86.td"
}

tablegen("X86GenRegisterBank") {
  visibility = [ ":LLVMX86CodeGen" ]
  args = [ "-gen-register-bank" ]
  td_file = "X86.td"
}

if (x86_gen_fold_tables) {
  tablegen("X86GenFoldTables") {
    visibility = [ ":LLVMX86CodeGen" ]
    args = [ "-gen-x86-fold-tables" ]
    td_file = "X86.td"
  }
}

static_library("LLVMX86CodeGen") {
  deps = [
    ":X86GenCallingConv",
    ":X86GenDAGISel",
    ":X86GenEVEX2VEXTables",
    ":X86GenFastISel",
    ":X86GenGlobalISel",
    ":X86GenRegisterBank",
    "MCTargetDesc",
    "TargetInfo",
    "//llvm/include/llvm/Config:llvm-config",
    "//llvm/lib/Analysis",
    "//llvm/lib/CodeGen",
    "//llvm/lib/CodeGen/AsmPrinter",
    "//llvm/lib/CodeGen/GlobalISel",
    "//llvm/lib/CodeGen/SelectionDAG",
    "//llvm/lib/IR",
    "//llvm/lib/MC",
    "//llvm/lib/Support",
    "//llvm/lib/Target",
    "//llvm/lib/Transforms/CFGuard",
  ]
  if (x86_gen_fold_tables) {
    deps += [ ":X86GenFoldTables" ]
  }
  sources = [
    "X86AsmPrinter.cpp",
    "X86AvoidStoreForwardingBlocks.cpp",
    "X86AvoidTrailingCall.cpp",
    "X86CallFrameOptimization.cpp",
    "X86CallLowering.cpp",
    "X86CallingConv.cpp",
    "X86CmovConversion.cpp",
    "X86DiscriminateMemOps.cpp",
    "X86DomainReassignment.cpp",
    "X86EvexToVex.cpp",
    "X86ExpandPseudo.cpp",
    "X86FastISel.cpp",
    "X86FastTileConfig.cpp",
    "X86FixupBWInsts.cpp",
    "X86FixupLEAs.cpp",
    "X86FixupSetCC.cpp",
    "X86FlagsCopyLowering.cpp",
    "X86FloatingPoint.cpp",
    "X86FrameLowering.cpp",
    "X86ISelDAGToDAG.cpp",
    "X86ISelLowering.cpp",
    "X86IndirectBranchTracking.cpp",
    "X86IndirectThunks.cpp",
    "X86InsertPrefetch.cpp",
    "X86InsertWait.cpp",
    "X86InstCombineIntrinsic.cpp",
    "X86InstrFMA3Info.cpp",
    "X86InstrFoldTables.cpp",
    "X86InstrInfo.cpp",
    "X86InstructionSelector.cpp",
    "X86InterleavedAccess.cpp",
    "X86LegalizerInfo.cpp",
    "X86LoadValueInjectionLoadHardening.cpp",
    "X86LoadValueInjectionRetHardening.cpp",
    "X86LowerAMXIntrinsics.cpp",
    "X86LowerAMXType.cpp",
    "X86LowerTileCopy.cpp",
    "X86MCInstLower.cpp",
    "X86MachineFunctionInfo.cpp",
    "X86MacroFusion.cpp",
    "X86OptimizeLEAs.cpp",
    "X86PadShortFunction.cpp",
    "X86PartialReduction.cpp",
    "X86PreAMXConfig.cpp",
    "X86PreTileConfig.cpp",
    "X86RegisterBankInfo.cpp",
    "X86RegisterInfo.cpp",
    "X86SelectionDAGInfo.cpp",
    "X86ShuffleDecodeConstantPool.cpp",
    "X86SpeculativeExecutionSideEffectSuppression.cpp",
    "X86SpeculativeLoadHardening.cpp",
    "X86Subtarget.cpp",
    "X86TargetMachine.cpp",
    "X86TargetObjectFile.cpp",
    "X86TargetTransformInfo.cpp",
    "X86TileConfig.cpp",
    "X86VZeroUpper.cpp",
    "X86WinAllocaExpander.cpp",
    "X86WinEHState.cpp",
  ]
}

# This is a bit different from most build files: Due to this group
# having the directory's name, "//llvm/lib/Target/X86" will refer to this
# target, which pulls in the code in this directory *and all subdirectories*.
# For most other directories, "//llvm/lib/Foo" only pulls in the code directly
# in "llvm/lib/Foo". The forwarding targets in //llvm/lib/Target expect this
# different behavior.
group("X86") {
  deps = [
    ":LLVMX86CodeGen",
    "AsmParser",
    "Disassembler",
    "MCTargetDesc",
    "TargetInfo",
  ]
}
